// stores/counter.js
import { defineStore } from 'pinia';
import { ref, computed,inject } from "vue";
import {getuser} from "../api/login"
interface Book {
  logo?: string
  name?: number
}


const mychat:any = inject("mychat");


export const useCounterStore = defineStore('counter', {
  state: () => ({ 
    token: uni.getStorageSync('storage_key') 
    ? uni.getStorageSync('storage_key') : null,
  quanxian:uni.getStorageSync('quan') 
  ? uni.getStorageSync('quan') : null,
userData:uni.getStorageSync('userData') ?JSON.parse(uni.getStorageSync('userData')):{},
    user:  uni.getStorageSync('user_key') 
    ? JSON.parse(uni.getStorageSync('user_key'))  : {},
task: uni.getStorageSync('task') 
? JSON.parse(uni.getStorageSync('task'))  : []
,
 dizhi:uni.getStorageSync('dizhi')?uni.getStorageSync('dizhi'):'',


 shouData:{
    Offline: [],
    Online: [],
  },
  }),
  getters: {
    double: (state) => state.token
  },
  actions: {
instUser(data:any){
  this.userData=data

uni.setStorageSync('userData', JSON.stringify(data));

},
instquan(data:string){
this.quanxian=data


  uni.setStorageSync('quan', data);
  
  },


instShouData(data:any){

 
  this.shouData=data
},

   
    indizhi(e:string){
      uni.setStorageSync('dizhi', e);
      this.dizhi=e
    },
    increment(token: string) {
      this.token = token
  
      
 uni.setStorageSync('storage_key', token);
    },
    incrementask(tasks:any) {
      
    

      
 uni.setStorageSync('task', JSON.stringify(tasks));
 this.task = tasks
    },

    removeTquan(){
      this.quanxian=null
      uni.removeStorageSync('quan');
    },
    removeTkeen(){
      uni.removeStorageSync('storage_key');
      this.token=null
    },
    incrementName(user:Book) {
      this.user = user

      
 uni.setStorageSync('user_key', JSON.stringify(user));
    },

  },
})